package com.example.repository.impl;

import com.example.entity.School;
import com.example.repository.SchoolRepository;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

@Repository
@Transactional
public class SchoolRepositoryImpl implements SchoolRepository {

    @PersistenceContext
    private EntityManager entityManager;

    @Override
    public void add(School school) {
        entityManager.persist(school);
    }

    @Override
    public School getById(Integer id) {
        return entityManager.find(School.class, id);
    }

    @Override
    public void save(School school) {
        entityManager.merge(school);
    }
}
